/** 消息状态码 */
web_status = {
    SUCCESS: 0,
    FAIL: 500,
    WARNING: 301
};

//留言、评论加载
function loadComment(articleId){
    $.ajax({
        type:"get",
        url:"/Blog/getLeaveWords?articleId="+articleId,
        dataType: 'json',
        success:function (result) {
            var messageList=$('#message-list');
            messageList.html('');
            var html="";
            var data=result.data;
            if(result.code==web_status.SUCCESS){
                for(var index=1;index<=data.length;index++){
                    var dd=data[index-1];
                    messageList.append('<li class="zoomIn article" id="article_'+dd.id+'">'+
                        '<div class="comment-parent">'+
                        '<a name="remark-1"></a>'+
                        '<img src="image/admin_img.png"/>'+
                        '<div class="info">'+
                        '<span class="username">'+dd.membername+'</span>'+
                        '</div>'+
                        '<div class="comment-content">'+
                        dd.content+
                        '</div>'+
                        '<p class="info info-footer">'+
                        '<i class="fa fa-map-marker" aria-hidden="true"></i>'+
                        '<span>'+dd.memberaddress+'</span> '+
                        '<span class="comment-time">'+dd.createtime+'</span>'+
                        '<a href="javascript:;" class="btn-reply" data-targetid="'+dd.id+'" data-targetname="'+dd.membername+'">回复</a>'+
                        '</p>'+
                        '</div>'
                    );
                    loadChildComment(data[index-1],dd.id);
                    messageList.append('</li>');
                    var li=$('#article_'+dd.id);
                    li.append('<div class="replycontainer layui-hide">'+
                        '<form class="layui-form" action="">'+
                        '<input type="hidden" name="targetUserId" value="0">'+
                        '<div class="layui-row layui-col-space10">'+
                        '<div class=" layui-col-md4">'+
                        '<input type="text" name="membername" lay-verify="required" autocomplete="on" class="layui-input" placeholder="称呼（必填）">'+
                        '</div>'+
                        '<div class=" layui-col-md4">'+
                        '<input type="text" name="memberemail" lay-verify="required|email" autocomplete="on" class="layui-input" placeholder="邮箱（必填）">'+
                        '</div>'+
                        '<div class=" layui-col-md4">'+
                        '<input type="text" name="memberurl"   class="layui-input" placeholder="网址（不必填）">'+
                        '</div>'+
                        '</div>'+
                        '<div class="layui-form-item">'+
                        '<textarea  name="replyContent" lay-verify="replyContent|required"  placeholder="请输入回复内容" class="layui-textarea" style="min-height:80px;"></textarea>'+
                        '</div>'+
                        '<div class="layui-form-item layui-input-inline">'+
                        '<button class="layui-btn layui-btn-xs"    lay-submit="formReply" lay-filter="formReply">提交</button>'+
                        '</div>'+
                        '</form>'+
                        '</div>');
                }

            }
        }
    });
}

/**
 * 加载留言回复，递归加载
 * @param data
 * @param parentsId
 */
function loadChildComment(data,parentsId) {
    var parendArticle=$('#article_'+parentsId);
    //加载回复子节点
    if(data.children!=null&&data.children.length>0){
        for(var index=0;index<data.children.length;index++){
            var dd=data.children[index];
            parendArticle.append('<hr />'+
                '<div class="comment-child">'+
                '<a name="reply-1"></a>'+
                '<img src="image/admin_img.png">'+
                '<div class="info">'+
                '<span class="username">'+dd.membername+'</span>'+
                '<span style="padding-right:0;margin-left:-5px;">回复</span>'+
                '<span class="username">'+dd.parentname+'</span>'+
                '<span>'+dd.content+'</span>'+
                '</div>'+
                '<p class="info">'+
                '<i class="fa fa-map-marker" aria-hidden="true"></i>'+
                '<span>'+dd.memberaddress+'</span>'+
                '<span class="comment-time">'+dd.createtime+'</span>'+
                '<a href="javascript:;" class="btn-reply" data-targetid="'+dd.id+'" data-targetname="'+dd.membername+'">回复</a>'+
                '</p>'+
                '</div>');
            loadChildComment(data.children[index],parentsId);
        }
    }
}
